#define  _CRT_SECURE_NO_WARNINGS
int cmp(const void* a, const void* b) 
{
    return *(int*)a < *(int*)b;                
}
int thirdMax(int* nums, int numsSize) 
{
    qsort(nums, numsSize, sizeof(int), cmp);
    int count = 0, num = nums[0], index = 1;   
    while (index < numsSize) 
    {
        if (nums[index] != num)
        {
            num = nums[index];
            count++;
        }
        index++;
        if (count == 2) return num;         
    }
    return nums[0];                       
}
